[#include "../../../common/html.ftl" /]
[@html]
    [@head title="字典类型列表" css=["fw", "bootstrap-table"] /]
    [@body]
        [#--主体内容--]
        [@main ]
            <div class="am-g am-radius fw-tables">
                [#--表格主体内容--操作栏--]
                [@mainHeader]
                    [#--[@shiro.hasPermission name="system:dictType:add"]--]
                    <button class="am-btn am-btn-success am-radius" onclick="$.operate.addFull()">添加</button>
                    [#--[/@shiro.hasPermission]--]
                    [#--[@shiro.hasPermission name="system:dictType:remove"]--]
                    <button class="am-btn am-btn-danger am-radius multiple am-disabled" onclick="$.operate.removeAll()">删除</button>
                    [#--[/@shiro.hasPermission]--]
                    [#--[@shiro.hasPermission name="system:dictType:remove"]--]
                    <button id="fw-toolbar-edit" class="am-btn am-btn-black am-radius" onclick="refreshCache()">刷新缓存</button>
                    [#--[/@shiro.hasPermission]--]
                [/@mainHeader]

                [#--表格主体内容--搜索栏--]
                [@searchForm searchId="form-type-search" ]
                    <div class="am-form-group">
                        <input type="text" name="dictName" class="am-form-field am-input-sm am-radius" placeholder="字典名称">
                    </div>
                    <div class="am-form-group">
                        <input type="text" name="dictType" class="am-form-field am-input-sm am-radius" placeholder="字典类型">
                    </div>
                    <div class="am-form-group">
                        <div class="am-form-group am-form-icon">
                            <i class="am-icon-calendar"></i>
                            <input type="text" name="params[beginTime]" class="am-form-field am-input-sm am-radius" placeholder="创建时间-开始"
                                   data-am-datepicker readonly/>
                        </div>
                        <div class="am-form-group am-form-icon">
                            <i class="am-icon-calendar"></i>
                            <input type="text" name="params[endTime]" class="am-form-field am-input-sm am-radius" placeholder="创建时间-结束"
                                   data-am-datepicker readonly/>
                        </div>
                    </div>
                    <div class="am-form-group">
                        <select name="dictType" class="am-radius" data-am-selected placeholder="字典状态">
                            <option value=""></option>
                            [#list dict.getType("sys_dict_status") as dict]
                                <option value="${dict.dictValue}">${dict.dictLabel}</option>
                            [/#list]
                        </select>
                    </div>
                    <div class="am-form-group">
                        <select name="buildIn" class="am-radius" data-am-selected placeholder="是否内置字典">
                            <option value=""></option>
                            [#list dict.getType("sys_yes_no") as dict]
                                <option value="${dict.dictValue}">${dict.dictLabel}</option>
                            [/#list]
                        </select>
                    </div>
                [/@searchForm]

                <div class="fw-table">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        [/@main]

        [#--PC/APP 右侧悬浮按钮--]
        [@rightToolbar /]

        [@script js=["fw", "bootstrap-table"]]
            <script type="text/javascript">
                [#--var editFlag = "${hasPermission('system:dictType:edit')}";--]
                [#--var removeFlag = "${hasPermission('system:dictType:remove')}";--]
                [#--var listFlag = "${hasPermission('system:dictType:list')}";--]
                var editFlag = "";
                var removeFlag = "";
                var listFlag ="";
                var datas = ${convert.toJson(dict.getType("sys_dict_status"))};
                var datasYesNo = ${convert.toJson(dict.getType("sys_yes_no"))};
                var isAdministrator = ${convert.toJson(common.isAdministrator())};

                var prefix = ctx + "osfw/system/dict/type";

                $(function () {
                    var options = {
                        url: prefix + "/list",
                        createUrl: prefix + "/add",
                        updateUrl: prefix + "/edit/{id}",
                        removeUrl: prefix + "/remove",
                        sortName: "createTime",
                        sortOrder: "desc",
                        modalName: "类型",
                        uniqueId: "dictId",
                        layerHeight: isAdministrator ? 600: 400,
                        columns: [
                            {
                                checkbox: true
                            },
                            {
                                title: "序号",
                                formatter: function (value, row, index) {
                                    return $.table.serialNumber(index);
                                }
                            },
                            {
                                field: 'dictName',
                                title: '字典名称',
                                sortable: true
                            },
                            {
                                field: 'dictType',
                                title: '字典类型',
                                sortable: true,
                                formatter: function (value, row, index) {
                                    return '<a href="javascript:void(0)" title="打开详细列表" onclick="listDict(\'' + row.dictId + '\')">' + value + '</a>';
                                }
                            },
                            {
                                field: 'status',
                                title: '状态',
                                align: 'left',
                                formatter: function (value, row, index) {
                                    return $.table.selectDictLabel(datas, value);
                                }
                            },
                            {
                                visible: isAdministrator ? true : false,
                                switchable: isAdministrator ? true : false,
                                field: 'buildIn',
                                title: '系统内置',
                                formatter: function (value, row, index) {
                                    return $.table.selectDictLabel(datasYesNo, value);
                                }
                            },
                            {
                                field: 'createBy',
                                title: '创建人',
                            },
                            {
                                field: 'remark',
                                title: '备注',
                                formatter: function (value, row, index) {
                                    return $.table.tooltip(value, 15);
                                },
                                visible: false
                            },
                            {
                                title: '操作',
                                cellStyle: operCellStyle,
                                formatter: function (value, row, index) {
                                    var actions = [];
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.dictId + '\')">编辑</a> ');
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.dictId + '\')">删除</a> ');
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + listFlag + '" href="javascript:void(0)" onclick="listDict(\'' + row.dictId + '\')">详细列表</a>');
                                    return actions.join('');
                                }
                            }
                        ]
                    };
                    $.table.init(options);
                });

                /*字典列表-详细*/
                function listDict(dictId) {
                    var url = prefix + '/detail/' + dictId;
                    $.modal.openTab(dictId, "字典数据-详细列表", "am-icon-file-text-o", url);
                }

                /** 清理字典缓存 */
                function refreshCache() {
                    $.operate.get(prefix + "/refreshCache");
                }

            </script>
        [/@script]
    [/@body]
[/@html]
